package org.breezeiot.protodecode.protocol.qgdw3761.utils;

import org.breezeiot.protodecode.protocol.chargingpile.MsgDcsResult;
import org.breezeiot.protodecode.dataobject.gw.GwItemData;
import org.breezeiot.protodecode.dataobject.gw.ReqDataComm;
import org.breezeiot.protodecode.dataobject.gw.afn0C.Req1stDataF188;
import org.breezeiot.protodecode.dataobject.gw.afn0C.Req1stDataF7;
import org.breezeiot.protodecode.enums.DateFormatEnum;
import org.breezeiot.protodecode.enums.MeterTypeEnum;
import org.breezeiot.protodecode.enums.UnitCodeEnum;
import org.breezeiot.protodecode.utils.DateUtil;
import org.breezeiot.protodecode.utils.ProtocolGW_09Util;
import org.breezeiot.protodecode.utils.ProtocolUtils;
import org.breezeiot.protodecode.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2018-09-13.
 */
@Component
public class Gw09ClassOneUtil {

    private static Logger logger = LoggerFactory.getLogger(Gw09ClassOneUtil.class);
    private static final int TARIFF_NUM_DEFAULT = 4;// 目前集中器按费率数=4 上送任务数据

    public static MsgDcsResult parseClassOneData(byte[] msg, int from, boolean acd) throws Exception {
        String commAddr = String.format("%02X%02X%02X%02X", msg[8], msg[7], msg[10], msg[9]);

        int index = from;
        int fixlen = (msg[index] & 0x80) == 0 ? 2 : 8;
        if (acd) {
            fixlen += 2;
        }
        index++;
        MsgDcsResult gwResult = new MsgDcsResult();
        List<GwItemData> gwItemList = new ArrayList<GwItemData>();
        boolean skip = false;
        List<Integer> pnList;
        while ((index + fixlen) < msg.length) {
            skip = false;
            pnList = ProtocolGW_09Util.getPnListFromDA(msg[index + 1], msg[index]);
            int fn = ProtocolGW_09Util.getFnFromDT(msg[index + 3], msg[index + 2]);
            index += 4;
            for (Integer pn : pnList) {
                GwItemData item = new GwItemData();
                item.setFn(fn);
                item.setPn(pn);
                int n = 0;
                int midu = 0;
                try {
                    ReqDataComm reqDataComm = new ReqDataComm();
                    switch (fn) {
                        case 2:
                            reqDataComm.setValue("终端日历时钟:" + DateUtil.DateToLongStr(ProtocolGW_09Util.parseA1(msg, index)) + ";");// 终端抄表时间:yyyy-MM-dd HH:mm;
                            item.setData(reqDataComm);
                            index += 6;
                            break;
                        case 3:
                            reqDataComm = parseF3Frame(msg, index);// F1:0;F2:1;......
                            item.setData(reqDataComm);
                            index += 31;
                            break;
                        case 4:
                            reqDataComm = parseF4Frame(msg, index);
                            item.setData(reqDataComm);
                            index += 1;
                            break;
                        case 5:// 终端控制设置状态
                            reqDataComm = parseF5Frame(msg, index);
                            item.setData(reqDataComm);
                            index += 2 + 6 * 8 + 1;
                            break;
                        case 6:// 终端当前控制状态
                            reqDataComm = parseF6Frame(msg, index);
                            item.setData(reqDataComm);
                            index += 3 + 5 * 8 + 1;
                            break;
                        case 7:// 终端事件计数器当前值
                            reqDataComm = parseF7Frame(msg, index);
                            item.setData(reqDataComm);
                            index += 2;
                            break;
                        case 8:// 终端事件标志状态
                            reqDataComm = parseF8Frame(msg, index);
                            item.setData(reqDataComm);
                            index += 8;
                            break;
                        case 9:// 终端状态量及变位标志
                            reqDataComm = parseF9Frame(msg, index);
                            item.setData(reqDataComm);
                            index += 2;
                            break;
                        case 10:// 终端与主站当日、月通信流量
                            reqDataComm = parseF10Frame(msg, index);
                            item.setData(reqDataComm);
                            index += 8;
                            break;
                        case 11://终端集中抄表状态信息
                            reqDataComm = parseF11Frame(msg, index);
                            item.setData(reqDataComm);
                            n = ProtocolUtils.Unsignd(msg[index]);
                            index += 1 + n * 19;
                            break;
                        case 25:
                            reqDataComm = parseF25Frame(msg, index);
                            item.setData(reqDataComm);

                            index += 67;
                            break;
                        case 27:
                            reqDataComm = parseF27Frame(msg, index);
                            item.setData(reqDataComm);
                            index += 60;
                            break;
                        case 28:
                            reqDataComm = parseF28Frame(msg, index);
                            item.setData(reqDataComm);
                            index += 33;
                            break;
                        case 31:
                            reqDataComm = parseF31Frame(msg, index);
                            item.setData(reqDataComm);
                            index += 59;
                            break;
                        case 33:
                            reqDataComm = parseF33Frame(msg, index);
                            item.setData(reqDataComm);

                            n = ProtocolUtils.Unsignd(msg[index + 5]);
                            if (n == 0 || n == 255) {
                                n = TARIFF_NUM_DEFAULT;
                            }
                            index += 5 + 1 + (n + 1) * 5 + (n + 1) * 4 * 3;
                            break;
                        case 34:
                            reqDataComm = parseF34Frame(msg, index);
                            item.setData(reqDataComm);

                            n = ProtocolUtils.Unsignd(msg[index + 5]);
                            if (n == 0 || n == 255) {
                                n = TARIFF_NUM_DEFAULT;
                            }
                            index += 5 + 1 + (n + 1) * 5 + (n + 1) * 4 * 3;
                            break;
                        case 35:
                            reqDataComm = parseF35Frame(msg, index);
                            item.setData(reqDataComm);

                            n = ProtocolUtils.Unsignd(msg[index + 5]);
                            if (n == 0 || n == 255) {
                                n = TARIFF_NUM_DEFAULT;
                            }
                            index += 5 + 1 + (n + 1) * (3 + 4) * 2;
                            break;
                        case 36:
                            reqDataComm = parseF36Frame(msg, index);
                            item.setData(reqDataComm);

                            n = ProtocolUtils.Unsignd(msg[index + 5]);
                            if (n == 0 || n == 255) {
                                n = TARIFF_NUM_DEFAULT;
                            }
                            index += 5 + 1 + (n + 1) * (3 + 4) * 2;
                            break;
                        case 41:
                            reqDataComm = parseF41Frame(msg, index);
                            item.setData(reqDataComm);
                            n = ProtocolUtils.Unsignd(msg[index]);
                            index += 1 + (n + 1) * 4;
                            break;
                        case 42:
                            reqDataComm = parseF42Frame(msg, index);
                            item.setData(reqDataComm);
                            n = ProtocolUtils.Unsignd(msg[index]);
                            index += 1 + (n + 1) * 4;
                            break;
                        case 43:
                            reqDataComm = parseF43Frame(msg, index);
                            item.setData(reqDataComm);
                            n = ProtocolUtils.Unsignd(msg[index]);
                            index += 1 + (n + 1) * 4;
                            break;
                        case 44:
                            reqDataComm = parseF44Frame(msg, index);
                            item.setData(reqDataComm);
                            n = ProtocolUtils.Unsignd(msg[index]);
                            index += 1 + (n + 1) * 4;
                            break;
                        case 49:
                            reqDataComm = parseF49Frame(msg, index);
                            item.setData(reqDataComm);
                            index += 12;
                            break;
                        case 57:
                            reqDataComm = parseF57Frame(msg, index);
                            item.setData(reqDataComm);
                            n = ProtocolUtils.Unsignd(msg[index]);
                            index += 1 + (n - 1) * 2 * 6;
                            break;
                        case 58:
                            reqDataComm = parseF58Frame(msg, index);
                            item.setData(reqDataComm);
                            n = ProtocolUtils.Unsignd(msg[index]);
                            index += 1 + (n - 1) * 2 * 6 + 6;
                            break;
                        case 89:
                        case 90:
                        case 91:
                        case 92:
                        case 93:
                        case 94:
                        case 95:
                        case 96:
                        case 97:
                        case 98:
                        case 99:
                        case 100:
                        case 101:
                        case 102:
                        case 103:
                        case 105:
                        case 106:
                        case 107:
                        case 108:
                        case 109:
                        case 110:
                        case 111:
                        case 112:
                        case 113:
                        case 114:
                        case 115:
                        case 116:
                            reqDataComm = parseF89_116Frame(msg, index, fn);
                            item.setData(reqDataComm);
                            midu = ProtocolUtils.Unsignd(msg[index + 1]);
                            n = 0;
                            if (midu == 1) {
                                n = 4;
                            } else if (midu == 2) {
                                n = 2;
                            } else if (midu == 3) {
                                n = 1;
                            } else if (midu == 254) {
                                n = 12;
                            } else if (midu == 255) {
                                n = 60;
                            }
                            if ((fn >= 89 && fn <= 96) || (fn >= 100 && fn <= 103)) {
                                index += 2 + n * 3;
                            } else if ((fn >= 97 && fn <= 99) || (fn >= 113 && fn <= 116)) {
                                index += 2 + n * 2;
                            } else if (fn >= 105 && fn <= 112) {
                                index += 2 + n * 4;
                            }
                            break;
                        case 129:
                        case 130:
                        case 131:
                        case 132:
                            reqDataComm = parseF129_132Frame(msg, index, fn);
                            item.setData(reqDataComm);

                            n = ProtocolUtils.Unsignd(msg[index + 5]);
                            if (n == 0 || n == 255) {
                                n = TARIFF_NUM_DEFAULT;
                            }
                            if (fn == 129 || fn == 131) {
                                index += 5 + 1 + (n + 1) * 5;
                            } else {
                                index += 5 + 1 + (n + 1) * 4;
                            }
                            break;
                        case 161:
                            reqDataComm = parseF161Frame(msg, index);
                            item.setData(reqDataComm);
                            index += 18;
                            break;
                        case 165:
                            reqDataComm = parseF165Frame(msg, index);
                            item.setData(reqDataComm);
                            index += 23;
                            break;
                        case 166:
                            reqDataComm = parseF166Frame(msg, index);
                            item.setData(reqDataComm);
                            index += 29;
                            break;
                        case 167:
                            reqDataComm = parseF167Frame(msg, index);
                            item.setData(reqDataComm);
                            index += 41;
                            break;
                        case 168:
                            reqDataComm = parseF168Frame(msg, index);
                            item.setData(reqDataComm);
                            n = ProtocolUtils.Unsignd(msg[index + 5]);
                            index += 16 + n * 10;
                            break;
                        case 188:
                            reqDataComm = parseF188Frame(msg, index); //新天平台数据上报， 移除havingTask检查
                            item.setData(reqDataComm);
                            index += 49;
                            break;
                        case 210:
                            reqDataComm = parseF210Frame(msg, index);
                            item.setData(reqDataComm);
                            index += 37;
                            break;
                        default:
                            skip = true;
                            logger.warn("376.1协议处理==> 一类类数据中找不到PN=" + pn + "FN=" + fn + "的处理方法");
                    }
                    if (!skip) {
                        gwItemList.add(item);//新天平台数据上报， 移除havingTask检查
                    }
                } catch (Exception e) {
                    logger.warn("376.1协议处理==> 一类类数据 解析错误.", e);
                }
            }
        }
        gwResult.setData(gwItemList);
        gwResult.setSuccess(true);
        gwResult.setMessage("成功");
        return gwResult;
    }

    private static ReqDataComm parseF161Frame(byte[] byteValue, int index) {
        ReqDataComm reqData = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        resultString.append("终端抄表时间:").append(ProtocolGW_09Util.parseA15(byteValue, index)).append(";");// 终端抄表时间:yyyy-MM-dd
        // HH:mm;
        index = index + 5;
        resultString.append("电能表通断电状态:").append(ProtocolUtils.Unsignd(byteValue[index++])).append(";");//
        resultString.append("最近一次电能表远程控制通电时间:").append(ProtocolGW_09Util.parseA15(byteValue, index)).append(";");// 终端抄表时间:yyyy-MM-dd
        // HH:mm;
        index = index + 5;
        resultString.append("最近一次电能表远程控制断电时间:").append(ProtocolGW_09Util.parseA15(byteValue, index)).append(";");// 终端抄表时间:yyyy-MM-dd
        // HH:mm;
        index = index + 5;
        reqData.setValue(resultString.toString());
        return reqData;
    }

    private static ReqDataComm parseF165Frame(byte[] byteValue, int index) {
        ReqDataComm reqData = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        resultString.append("终端抄表时间:").append(ProtocolGW_09Util.parseA15(byteValue, index)).append(";");// 终端抄表时间:yyyy-MM-dd
        // HH:mm;
        index = index + 5;
        resultString.append("编程开关操作次数:").append(ProtocolUtils.byteToShort(byteValue[index + 1], byteValue[index])).append(";");//
        index = index + 2;
        resultString.append("最近一次编程开关操作时间:").append(ProtocolGW_09Util.parseA15(byteValue, index)).append(";");// 终端抄表时间:yyyy-MM-dd
        // HH:mm;
        index = index + 5;
        resultString.append("电能表尾盖打开次数:").append(ProtocolUtils.byteToShort(byteValue[index + 1], byteValue[index])).append(";");//
        index = index + 2;
        resultString.append("最近一次尾盖打开时间:").append(ProtocolGW_09Util.parseA15(byteValue, index)).append(";");// 终端抄表时间:yyyy-MM-dd
        // HH:mm;
        index = index + 5;
        reqData.setValue(resultString.toString());
        return reqData;
    }

    private static ReqDataComm parseF166Frame(byte[] byteValue, int index) {
        ReqDataComm reqData = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        resultString.append("终端抄表时间:").append(ProtocolGW_09Util.parseA15(byteValue, index)).append(";");// 终端抄表时间:yyyy-MM-dd
        // HH:mm;
        index = index + 5;
        resultString.append("电能表时钟修改次数:").append(ProtocolUtils.byteToShort(byteValue[index + 1], byteValue[index])).append(";");//
        index = index + 2;
        resultString.append("电能表最近一次时钟修改时间:").append(ProtocolGW_09Util.parseA15(byteValue, index)).append(";");// 终端抄表时间:yyyy-MM-dd
        // HH:mm;
        index = index + 5;
        resultString.append("电能表时段参数修改次数:").append(ProtocolUtils.byteToShort(byteValue[index + 1], byteValue[index])).append(";");//
        index = index + 2;
        resultString.append("最近一次电能表时段参数修改时间:").append(ProtocolGW_09Util.parseA15(byteValue, index)).append(";");// 终端抄表时间:yyyy-MM-dd
        // HH:mm;
        index = index + 5;
        reqData.setValue(resultString.toString());
        return reqData;
    }

    private static ReqDataComm parseF167Frame(byte[] byteValue, int index) {
        ReqDataComm reqData = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        resultString.append("终端抄表时间:").append(ProtocolGW_09Util.parseA15(byteValue, index)).append(";");// 终端抄表时间:yyyy-MM-dd
        // HH:mm;
        index = index + 5;
        resultString.append("购电次数:").append(ProtocolGW_09Util.parseA8(byteValue, index)).append(";");//
        index = index + 2;
        resultString.append("剩余金额:").append(ProtocolGW_09Util.parseA14(byteValue, index)).append(";");//
        index = index + 5;
        resultString.append("累计购电金额:").append(ProtocolGW_09Util.parseA14(byteValue, index)).append(";");//
        index = index + 5;
        resultString.append("剩余电量:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("kWh;");//
        index = index + 4;
        resultString.append("透支电量:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("kWh;");//
        index = index + 4;
        resultString.append("累计购电量:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("kWh;");//
        index = index + 4;
        resultString.append("赊欠门限电量:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("kWh;");//
        index = index + 4;
        resultString.append("报警电量:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("kWh;");//
        index = index + 4;
        resultString.append("故障电量:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("kWh;");//
        index = index + 4;
        reqData.setValue(resultString.toString());
        return reqData;
    }

    private static ReqDataComm parseF168Frame(byte[] byteValue, int index) {
        ReqDataComm reqData = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        resultString.append("终端抄表时间:").append(ProtocolGW_09Util.parseA15(byteValue, index)).append(";");// 终端抄表时间:yyyy-MM-dd
        // HH:mm;
        index = index + 5;
        int tariffnum = ProtocolUtils.byteToShort(byteValue[index + 1], byteValue[index]);
        if (tariffnum ==0 || tariffnum > 96) {
            tariffnum = TARIFF_NUM_DEFAULT;
        }
        resultString.append("费率数:").append(tariffnum).append(";");// 费率数:1;
        index = index + 2;
        resultString.append("已结有功总电能:").append(ProtocolGW_09Util.parseA14(byteValue, index)).append("kWh;");// 当前正向有功总电能示值:100kWh;
        index = index + 5;
        for (int i = 0;i < tariffnum; i++) {
            resultString.append("已结费率").append((i + 1)).append("正向有功总电能:").append(ProtocolGW_09Util.parseA14(byteValue, index)).append("kWh;");// 费率i正向有功电能示值:100kWh;
            index = index + 5;
        }
        resultString.append("未结有功总电能:").append(ProtocolGW_09Util.parseA14(byteValue, index)).append("kWh;");// 当前正向有功总电能示值:100kWh;
        index = index + 5;
        for (int i = 0;i < tariffnum; i++) {
            resultString.append("未结费率").append((i + 1)).append("正向有功总电能:").append(ProtocolGW_09Util.parseA14(byteValue, index)).append("kWh;");// 费率i正向有功电能示值:100kWh;
            index = index + 5;
        }

        reqData.setValue(resultString.toString());
        return reqData;
    }


    private static ReqDataComm parseF210Frame(byte[] byteValue, int index) {
        ReqDataComm reqData = new ReqDataComm();
        StringBuilder builder = new StringBuilder();
        builder.append("抄表时间:").append(ProtocolGW_09Util.parseA15(byteValue, index)).append(";");
        index += 5;

        int intValue, decValue;
        float floatValue;
        byte[] bytes = new byte[4];
        System.arraycopy(byteValue, index, bytes, 0, 4);
        floatValue = ProtocolUtils.byte2IEEE754Float(turnHighLow(bytes));
        index += 4;
        builder.append("瞬时流量:").append(floatValue).append(";");

        System.arraycopy(byteValue, index, bytes, 0, 4);
        floatValue = ProtocolUtils.byte2IEEE754Float(turnHighLow(bytes));
        index += 4;
        builder.append("瞬时流速:").append(floatValue).append(";");

        System.arraycopy(byteValue, index, bytes, 0, 4);
        floatValue = ProtocolUtils.byte2IEEE754Float(turnHighLow(bytes));
        index += 4;
        builder.append("流量百分比:").append(floatValue).append(";");

        System.arraycopy(byteValue, index, bytes, 0, 4);
        floatValue = ProtocolUtils.byte2IEEE754Float(turnHighLow(bytes));
        index += 4;
        builder.append("电导率:").append(floatValue).append(";");

        System.arraycopy(byteValue, index, bytes, 0, 4);
        intValue = ProtocolUtils.byteToInteger(turnLowHigh(bytes), 0);
        index += 4;
        System.arraycopy(byteValue, index, bytes, 0, 4);
        decValue = ProtocolUtils.byteToInteger(turnLowHigh(bytes), 0);
        index += 4;
        builder.append("正向流量累计:").append(intValue).append(".").append(decValue).append(";");

        System.arraycopy(byteValue, index, bytes, 0, 4);
        intValue = ProtocolUtils.byteToInteger(turnLowHigh(bytes), 0);
        index += 4;
        System.arraycopy(byteValue, index, bytes, 0, 4);
        decValue = ProtocolUtils.byteToInteger(turnLowHigh(bytes), 0);
        builder.append("反向流量累计:").append(intValue).append(".").append(decValue).append(";");

        reqData.setValue(builder.toString());
        return reqData;
    }

    private static byte[] turnHighLow(byte[] value) {
        if (value == null || value.length != 4) {
            logger.info("byte[] is null or it's length != 4.");
            return new byte[4];
        }
        byte[] result = new byte[4];
        result[0] = value[2];
        result[1] = value[3];
        result[2] = value[0];
        result[3] = value[1];
        return result;
    }

    private static byte[] turnLowHigh(byte[] value) {
        if (value == null || value.length != 4) {
            logger.info("byte[] is null or it's length != 4.");
            return new byte[4];
        }
        byte[] result = new byte[4];
        result[3] = value[2];
        result[2] = value[3];
        result[1] = value[0];
        result[0] = value[1];
        return result;
    }

    private static ReqDataComm parseF188Frame(byte[] byteValue, int index) {
        ReqDataComm reqData = new ReqDataComm();
        Req1stDataF188 f188 = new Req1stDataF188();
        reqData.setData(f188);
        int length = index + 49;
        if (byteValue.length < length) {
            logger.error("报文长度不足，实际长度：{}，长度至少:{}", byteValue.length, length);
            reqData.setValue("报文长度不足，实际长度：" + byteValue.length + "，长度至少:" + length);
            return reqData;
        }
        StringBuffer resultString = new StringBuffer("");
        String unit = "";
        resultString.append("终端抄表时间:").append(ProtocolGW_09Util.parseA15(byteValue, index)).append(";");// 终端抄表时间:yyyy-MM-dd
        f188.setRtuDataTime(ProtocolGW_09Util.parseDateTime(byteValue, index, DateFormatEnum.A15));
        // HH:mm;
        index = index + 5;
        String type = Integer.toHexString(ProtocolUtils.Unsignd(byteValue[index++]));
        resultString.append("仪表类型:").append(type).append(";");
        f188.setMeterType(type);
        // 10,11,12,13,19,30
        BigDecimal value;
        if (MeterTypeEnum.METER_WATER_COLD.getValue().equals(type) || MeterTypeEnum.METER_WATER.getValue().equals(type) || MeterTypeEnum.METER_WATER_PURE.getValue().equals(type)
                || MeterTypeEnum.METER_WATER_HOT.getValue().equals(type) || MeterTypeEnum.METER_WATER_ELEC.getValue().equals(type) ||
                MeterTypeEnum.METER_GAS.getValue().equals(type) || MeterTypeEnum.METER_WATER_COLD_17.getValue().equals(type)) {
            unit = StringUtil.AddjustLength(Integer.toHexString(byteValue[index] & 0xFF), 2, "0");
            value = ProtocolGW_09Util.parseA220(byteValue, index);
            resultString.append("当前累积流量:").append(value + UnitCodeEnum.getText(unit)).append(";");
            f188.setCurCumulant(value);

            index = index + 5;
            unit = StringUtil.AddjustLength(Integer.toHexString(byteValue[index] & 0xFF), 2, "0");
            value = ProtocolGW_09Util.parseA220(byteValue, index);
            f188.setBillDateCumulant(value);
            resultString.append("结算日累积流量:").append(value + UnitCodeEnum.getText(unit)).append(";");

            index = index + 5;
            index = index + 21;// 保留21个字节
            value = ProtocolGW_09Util.parseA10(byteValue, index);
            f188.setWorkHours(value == null ? null : value.intValue());
            resultString.append("累积工作时间:").append(value).append("h;");// 累积工作时间
            index = index + 3;
            String realTime = ProtocolUtils.getByteToHexStringDesc(byteValue, index, 7, "");
            if (!(realTime.indexOf("0000") == 0
                    || realTime.indexOf("EEEE") == 0 || realTime.indexOf("eeee") == 0
                    || realTime.indexOf("FFFF") == 0 || realTime.indexOf("ffff") == 0)) {
                realTime = ProtocolGW_09Util.parseA32(byteValue, index);
                f188.setRealDataTime(DateUtil.LongStrToDate(realTime));
            } else {
                f188.setRealDataTime(f188.getRtuDataTime());
            }
            resultString.append("实时时间:").append(realTime).append(";");// 实时时间
            index = index + 7;

            String st = String.format("%02X", 0xFF & byteValue[index]);
            if (!(st.equalsIgnoreCase("EE") || st.equalsIgnoreCase("FF"))) {
                int valveStatus = ((byteValue[index]) & 0x03);// 阀门状态
                f188.setPowerStatus((short) valveStatus);
                resultString.append("阀门状态:").append(valveStatus).append(";");
                int u = ((byteValue[index] >> 2) & 0x01);// 电池电压
                f188.setBatteryVoltageStatus((short) u);
                resultString.append("电池电压:").append(u).append(";");
            }
            // 20,21
        } else if (MeterTypeEnum.METER_HEAT_HOT.getValue().equals(type) || MeterTypeEnum.METER_HEAT_COLD.getValue().equals(type)) {
            unit = StringUtil.AddjustLength(Integer.toHexString(byteValue[index] & 0xFF), 2, "0");
            value = ProtocolGW_09Util.parseA220(byteValue, index);
            f188.setBillDateCumulant(value);
            resultString.append("结算日热量:").append(value + UnitCodeEnum.getText(unit)).append(";");

            index = index + 5;
            unit = StringUtil.AddjustLength(Integer.toHexString(byteValue[index] & 0xFF), 2, "0");
            value = ProtocolGW_09Util.parseA220(byteValue, index);
            f188.setCurCumulant(value);
            resultString.append("当前热量:").append(value + UnitCodeEnum.getText(unit)).append(";");

            index = index + 5;
            unit = StringUtil.AddjustLength(Integer.toHexString(byteValue[index] & 0xFF), 2, "0");
            value = ProtocolGW_09Util.parseA10(byteValue, index);
            f188.setHotPower(value);
            resultString.append("热功率:").append(value + UnitCodeEnum.getText(unit)).append(";");// 热功率

            index = index + 5;
            unit = StringUtil.AddjustLength(Integer.toHexString(byteValue[index] & 0xFF), 2, "0");
            value = ProtocolGW_09Util.parseA10(byteValue, index);
            f188.setFlow(value);
            resultString.append("流量:").append(value + UnitCodeEnum.getText(unit)).append(";");// 流量

            index = index + 5;
            unit = StringUtil.AddjustLength(Integer.toHexString(byteValue[index] & 0xFF), 2, "0");
            value = ProtocolGW_09Util.parseA10(byteValue, index);
            f188.setTotalFlow(value);
            resultString.append("累积流量:").append(value + UnitCodeEnum.getText(unit)).append(";");// 累积流量
            index = index + 5;

            value = ProtocolGW_09Util.parseA31(byteValue, index);
            f188.setSupplyWaterTemp(value);
            resultString.append("供水温度:").append(value).append("℃;");// 供水温度
            index = index + 3;

            value = ProtocolGW_09Util.parseA31(byteValue, index);
            f188.setBackWaterTemp(value);
            resultString.append("回水温度:").append(value).append("℃;");// 回水温度
            index = index + 3;

            value = ProtocolGW_09Util.parseA10(byteValue, index);
            f188.setWorkHours(value == null ? null : value.intValue());
            resultString.append("累积工作时间:").append(value).append("h;");// 累积工作时间
            index = index + 3;

            String realTime = ProtocolGW_09Util.parseA32(byteValue, index);
            f188.setRealDataTime(DateUtil.LongStrToDate(realTime));
            resultString.append("实时时间:").append(realTime).append(";");// 实时时间
            index = index + 7;

            int valveStatus = ((byteValue[index]) & 0x03);// 阀门状态
            f188.setPowerStatus((short) valveStatus);
            resultString.append("阀门状态:").append(valveStatus).append(";");

            int u = ((byteValue[index] >> 2) & 0x01);// 电池电压
            f188.setBatteryVoltageStatus((short) u);
            resultString.append("电池电压:").append(u).append(";");
        }
        reqData.setValue(resultString.toString());
        return reqData;
    }

    private static ReqDataComm parseF89_116Frame(byte[] byteValue, int index, int fn) {
        ReqDataComm reqData = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        resultString.append("小时冻结类数据时标:").append(Td_h(byteValue, index)).append(";");
        int m = ProtocolUtils.Unsignd(byteValue[index + 1]);
        int num = 0;
        if (m == 1) {
            num = 4;
        } else if (m == 2) {
            num = 2;
        } else if (m == 3) {
            num = 1;
        } else if (m == 254) {
            num = 12;
        } else if (m == 255) {
            num = 60;
        }
        index = index + 2;
        if (fn == 89 || fn == 90 || fn == 91 || fn == 92 || fn == 93 || fn == 94 || fn == 95 || fn == 96) {
            for (int i = 0; i < num; i++) {
                resultString.append("功率").append((i + 1)).append(":").append(ProtocolGW_09Util.parseA9(byteValue, index)).append(";");
                index = index + 3;
            }
        } else if (fn == 97 || fn == 98 || fn == 99) {
            for (int i = 0; i < num; i++) {
                resultString.append("电压").append((i + 1)).append(":").append(ProtocolGW_09Util.parseA7(byteValue, index)).append(";");
                index = index + 2;
            }
        } else if (fn == 100 || fn == 101 || fn == 102 || fn == 103) {
            for (int i = 0; i < num; i++) {
                resultString.append("电流").append((i + 1)).append(":").append(ProtocolGW_09Util.parseA25(byteValue, index)).append(";");
                index = index + 3;
            }
        } else if (fn == 105 || fn == 106 || fn == 107 | fn == 108) {
            for (int i = 0; i < num; i++) {
                resultString.append("电量").append((i + 1)).append(":").append(ProtocolGW_09Util.parseA13(byteValue, index)).append(";");
                index = index + 4;
            }
        } else if (fn == 109 || fn == 110 || fn == 111 | fn == 112) {
            for (int i = 0; i < num; i++) {
                resultString.append("电能示值").append((i + 1)).append(":").append(ProtocolGW_09Util.parseA11(byteValue, index)).append(";");
                index = index + 4;
            }
        } else if (fn == 113 || fn == 114 || fn == 115 | fn == 116) {
            for (int i = 0; i < num; i++) {
                resultString.append("功率因素").append((i + 1)).append(":").append(ProtocolGW_09Util.parseA5(byteValue, index)).append(";");
                index = index + 2;
            }
        }
        reqData.setValue(resultString.toString());
        return reqData;
    }

    private static ReqDataComm parseF57Frame(byte[] byteValue, int index) {
        ReqDataComm reqData = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        int num = ProtocolUtils.Unsignd(byteValue[index++]);
        resultString.append("谐波次数:").append(num).append(";");//
        for (int i = 1; i < num; i++) {
            resultString.append("A相").append((i + 1)).append("次谐波电压:").append(ProtocolGW_09Util.parseA7(byteValue, index)).append("V;");
            index = index + 2;
        }
        for (int i = 1; i < num; i++) {
            resultString.append("B相").append((i + 1)).append("次谐波电压:").append(ProtocolGW_09Util.parseA7(byteValue, index)).append("V;");
            index = index + 2;
        }
        for (int i = 1; i < num; i++) {
            resultString.append("C相").append((i + 1)).append("次谐波电压:").append(ProtocolGW_09Util.parseA7(byteValue, index)).append("V;");
            index = index + 2;
        }
        for (int i = 1; i < num; i++) {
            resultString.append("A相").append((i + 1)).append("次谐波电流:").append(ProtocolGW_09Util.parseA7(byteValue, index)).append("A;");
            index = index + 2;
        }
        for (int i = 1; i < num; i++) {
            resultString.append("B相").append((i + 1)).append("次谐波电流:").append(ProtocolGW_09Util.parseA7(byteValue, index)).append("A;");
            index = index + 2;
        }
        for (int i = 1; i < num; i++) {
            resultString.append("C相").append((i + 1)).append("次谐波电流:").append(ProtocolGW_09Util.parseA7(byteValue, index)).append("A;");
            index = index + 2;
        }
        reqData.setValue(resultString.toString());
        return reqData;
    }

    private static ReqDataComm parseF58Frame(byte[] byteValue, int index) {
        ReqDataComm reqData = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        int num = ProtocolUtils.Unsignd(byteValue[index++]);
        resultString.append("谐波次数:").append(num).append(";");//
        resultString.append("A相总谐波电压含有率:").append(ProtocolGW_09Util.parseA5(byteValue, index)).append("%;");
        index = index + 2;
        for (int i = 1; i < num; i++) {
            resultString.append("A相").append((i + 1)).append("次谐波电压含有率:").append(ProtocolGW_09Util.parseA7(byteValue, index)).append("%;");
            index = index + 2;
        }
        resultString.append("B相总谐波电压含有率:").append(ProtocolGW_09Util.parseA5(byteValue, index)).append("%;");
        index = index + 2;
        for (int i = 1; i < num; i++) {
            resultString.append("B相").append((i + 1)).append("次谐波电压含有率:").append(ProtocolGW_09Util.parseA7(byteValue, index)).append("%;");
            index = index + 2;
        }
        resultString.append("C相总谐波电压含有率:").append(ProtocolGW_09Util.parseA5(byteValue, index)).append("%;");
        index = index + 2;
        for (int i = 1; i < num; i++) {
            resultString.append("C相").append((i + 1)).append("次谐波电压含有率:").append(ProtocolGW_09Util.parseA7(byteValue, index)).append("%;");
            index = index + 2;
        }
        resultString.append("A相总谐波电流含有率:").append(ProtocolGW_09Util.parseA5(byteValue, index)).append("%;");
        index = index + 2;
        for (int i = 1; i < num; i++) {
            resultString.append("A相").append((i + 1)).append("次谐波电流含有率:").append(ProtocolGW_09Util.parseA7(byteValue, index)).append("%;");
            index = index + 2;
        }
        resultString.append("B相总谐波电流含有率:").append(ProtocolGW_09Util.parseA5(byteValue, index)).append("%;");
        index = index + 2;
        for (int i = 1; i < num; i++) {
            resultString.append("B相").append((i + 1)).append("次谐波电流含有率:").append(ProtocolGW_09Util.parseA7(byteValue, index)).append("%;");
            index = index + 2;
        }
        resultString.append("C相总谐波电流含有率:").append(ProtocolGW_09Util.parseA5(byteValue, index)).append("%;");
        index = index + 2;
        for (int i = 1; i < num; i++) {
            resultString.append("C相").append((i + 1)).append("次谐波电流含有率:").append(ProtocolGW_09Util.parseA7(byteValue, index)).append("%;");
            index = index + 2;
        }
        reqData.setValue(resultString.toString());
        return reqData;
    }

    private static ReqDataComm parseF49Frame(byte[] byteValue, int index) {
        ReqDataComm reqData = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        resultString.append("Uab/Ua相位角:").append(ProtocolGW_09Util.parseA5(byteValue, index)).append(";");
        index = index + 2;
        resultString.append("Ub相位角:").append(ProtocolGW_09Util.parseA5(byteValue, index)).append(";");
        index = index + 2;
        resultString.append("Ucb/Uc相位角:").append(ProtocolGW_09Util.parseA5(byteValue, index)).append(";");
        index = index + 2;
        resultString.append("Ia相位角:").append(ProtocolGW_09Util.parseA5(byteValue, index)).append(";");
        index = index + 2;
        resultString.append("Ib相位角:").append(ProtocolGW_09Util.parseA5(byteValue, index)).append(";");
        index = index + 2;
        resultString.append("Ic相位角:").append(ProtocolGW_09Util.parseA5(byteValue, index)).append(";");
        index = index + 2;
        reqData.setValue(resultString.toString());
        return reqData;
    }

    private static ReqDataComm parseF41Frame(byte[] byteValue, int index) {
        ReqDataComm reqData = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        int tariffnum = ProtocolUtils.Unsignd(byteValue[index++]);
        if (tariffnum ==0 || tariffnum > 96) {
            tariffnum = TARIFF_NUM_DEFAULT;
        }
        resultString.append("费率数:").append(tariffnum).append(";");// 费率数:1;
        resultString.append("当日正向有功总电能量:").append(ProtocolGW_09Util.parseA13(byteValue, index)).append("kWh;");//
        index = index + 4;
        for (int i = 0;i < tariffnum; i++) {
            resultString.append("当日费率").append((i + 1)).append("正向有功电能量:").append(ProtocolGW_09Util.parseA13(byteValue, index)).append("kWh;");//
            index = index + 4;
        }
        reqData.setValue(resultString.toString());
        return reqData;
    }

    private static ReqDataComm parseF42Frame(byte[] byteValue, int index) {
        ReqDataComm reqData = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        int tariffnum = ProtocolUtils.Unsignd(byteValue[index++]);
        if (tariffnum ==0 || tariffnum > 96) {
            tariffnum = TARIFF_NUM_DEFAULT;
        }
        resultString.append("费率数:").append(tariffnum).append(";");// 费率数:1;
        resultString.append("当日正向无功总电能量:").append(ProtocolGW_09Util.parseA13(byteValue, index)).append("kvarh");//
        index = index + 4;
        for (int i = 0;i < tariffnum; i++) {
            resultString.append("当日费率").append((i + 1)).append("正向无功电能量:").append(ProtocolGW_09Util.parseA13(byteValue, index)).append("kvarh;");//
            index = index + 4;
        }
        reqData.setValue(resultString.toString());
        return reqData;
    }

    private static ReqDataComm parseF43Frame(byte[] byteValue, int index) {
        ReqDataComm reqData = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        int tariffnum = ProtocolUtils.Unsignd(byteValue[index++]);
        if (tariffnum ==0 || tariffnum > 96) {
            tariffnum = TARIFF_NUM_DEFAULT;
        }
        resultString.append("费率数:").append(tariffnum).append(";");// 费率数:1;
        resultString.append("当日反向有功总电能量:").append(ProtocolGW_09Util.parseA13(byteValue, index).toString()).append("kWh;");//
        index = index + 4;
        for (int i = 0;i < tariffnum; i++) {
            resultString.append("当日费率").append((i + 1)).append("反向无功电能量:").append(ProtocolGW_09Util.parseA13(byteValue, index)).append("kWh;");//
            index = index + 4;
        }
        reqData.setValue(resultString.toString());
        return reqData;
    }

    private static ReqDataComm parseF44Frame(byte[] byteValue, int index) {
        ReqDataComm reqData = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        int tariffnum = ProtocolUtils.Unsignd(byteValue[index++]);
        if (tariffnum ==0 || tariffnum > 96) {
            tariffnum = TARIFF_NUM_DEFAULT;
        }
        resultString.append("费率数:").append(tariffnum).append(";");// 费率数:1;
        resultString.append("当日反向无功总电能量:").append(ProtocolGW_09Util.parseA13(byteValue, index)).append("kvarh");//
        index = index + 4;
        for (int i = 0;i < tariffnum; i++) {
            resultString.append("当日费率").append((i + 1)).append("反向无功电能量:").append(ProtocolGW_09Util.parseA13(byteValue, index)).append("kvarh;");//
            index = index + 4;
        }
        reqData.setValue(resultString.toString());
        return reqData;
    }

    private static ReqDataComm parseF33Frame(byte[] byteValue, int index) {
        ReqDataComm reqData = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        resultString.append("终端抄表时间:").append(ProtocolGW_09Util.parseA15(byteValue, index)).append(";");// 终端抄表时间:yyyy-MM-dd
        // HH:mm;
        index = index + 5;
        int tariffnum = ProtocolUtils.Unsignd(byteValue[index++]);
        if (tariffnum ==0 || tariffnum > 96) {
            tariffnum = TARIFF_NUM_DEFAULT;
        }
        resultString.append("费率数:").append(tariffnum).append(";");// 费率数:1;
        resultString.append("当前正向有功总电能示值:").append(ProtocolGW_09Util.parseA14(byteValue, index)).append("kWh;");// 当前正向有功总电能示值:100kWh;
        index = index + 5;
        for (int i = 0;i < tariffnum; i++) {
            resultString.append("当前费率").append((i + 1)).append("正向有功电能示值:").append(ProtocolGW_09Util.parseA14(byteValue, index)).append("kWh;");// 费率i正向有功电能示值:100kWh;
            index = index + 5;
        }
        resultString.append("当前正向无功（组合无功1）总电能示值:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("kvarh;");// 当前正向无功（组合无功1）总电能示值:100kWh;
        index = index + 4;
        for (int i = 0;i < tariffnum; i++) {
            resultString.append("当前费率").append((i + 1)).append("正向无功（组合无功1）总电能示值:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("kvarh;");// 当前费率i正向无功（组合无功1）总电能示值:100kWh;
            index = index + 4;
        }
        resultString.append("当前一象限无功总电能示值:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("kvarh;");//
        index = index + 4;
        for (int i = 0;i < tariffnum; i++) {
            resultString.append("当前一象限费率").append((i + 1)).append("无功总电能示值:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("kvarh;");//
            index = index + 4;
        }
        resultString.append("当前四象限无功总电能示值:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("kvarh;");//
        index = index + 4;
        for (int i = 0;i < tariffnum; i++) {
            resultString.append("当前四象限费率").append((i + 1)).append("无功总电能示值:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("kvarh;");//
            index = index + 4;
        }
        reqData.setValue(resultString.toString());
        return reqData;
    }

    private static ReqDataComm parseF34Frame(byte[] byteValue, int index) {
        ReqDataComm reqData = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        resultString.append("终端抄表时间:").append(ProtocolGW_09Util.parseA15(byteValue, index)).append(";");// 终端抄表时间:yyyy-MM-dd
        // HH:mm;
        index = index + 5;
        int tariffnum = ProtocolUtils.Unsignd(byteValue[index++]);
        if (tariffnum ==0 || tariffnum > 96) {
            tariffnum = TARIFF_NUM_DEFAULT;
        }
        resultString.append("费率数:").append(tariffnum).append(";");// 费率数:1;
        resultString.append("当前反向有功总电能示值:").append(ProtocolGW_09Util.parseA14(byteValue, index)).append("kWh;");// 当前反向有功总电能示值:100kWh;
        index = index + 5;
        for (int i = 0;i < tariffnum; i++) {
            resultString.append("当前费率").append((i + 1)).append("反向有功总电能示值:").append(ProtocolGW_09Util.parseA14(byteValue, index)).append("kWh;");// 费率i反向有功总电能示值:100kWh;
            index = index + 5;
        }
        resultString.append("当前反向无功（组合无功2）总电能示值:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("kvarh;");// 当前反向无功（组合无功2）总电能示值:100kWh;
        index = index + 4;
        for (int i = 0;i < tariffnum; i++) {
            resultString.append("当前费率").append((i + 1)).append("反向无功（组合无功2）总电能示值:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("kvarh;");// 当前费率i反向无功（组合无功2）总电能示值:100kWh;
            index = index + 4;
        }
        resultString.append("当前二象限无功总电能示值:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("kvarh;");//
        index = index + 4;
        for (int i = 0;i < tariffnum; i++) {
            resultString.append("当前二象限费率").append((i + 1)).append("无功总电能示值:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("kvarh;");//
            index = index + 4;
        }
        resultString.append("当前三象限无功总电能示值:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("kvarh;");//
        index = index + 4;
        for (int i = 0;i < tariffnum; i++) {
            resultString.append("当前三象限费率").append((i + 1)).append("无功总电能示值:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("kvarh;");//
            index = index + 4;
        }
        reqData.setValue(resultString.toString());
        return reqData;
    }

    private static ReqDataComm parseF35Frame(byte[] byteValue, int index) {
        return null;
    }

    private static ReqDataComm parseF36Frame(byte[] byteValue, int index) {
        return null;
    }

    private static ReqDataComm parseF31Frame(byte[] byteValue, int index) {
        ReqDataComm reqData = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        resultString.append("终端抄表时间:").append(ProtocolGW_09Util.parseA15(byteValue, index)).append(";");// 终端抄表时间:yyyy-MM-dd
        // HH:mm;
        index = index + 5;
        resultString.append("当前A相正向有功电能示值:").append(ProtocolGW_09Util.parseA14(byteValue, index)).append("kWh;");// 当前A相正向有功电能示值:100kWh;
        index = index + 5;
        resultString.append("当前A相反向有功电能示值:").append(ProtocolGW_09Util.parseA14(byteValue, index)).append("kWh;");// 当前A相反向有功电能示值:100kWh;
        index = index + 5;
        resultString.append("当前A相组合无功1电能示值:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("Kvarh;");// 当前A相组合无功1电能示值:100Kvarh;
        index = index + 4;
        resultString.append("当前A相组合无功2电能示值:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("Kvarh;");// 当前A相组合无功2电能示值:100Kvarh;
        index = index + 4;
        resultString.append("当前B相正向有功电能示值:").append(ProtocolGW_09Util.parseA14(byteValue, index)).append("kWh;");// 当前B相正向有功电能示值:100kWh;
        index = index + 5;
        resultString.append("当前B相反向有功电能示值:").append(ProtocolGW_09Util.parseA14(byteValue, index)).append("kWh;");// 当前B相反向有功电能示值:100kWh;
        index = index + 5;
        resultString.append("当前B相组合无功1电能示值:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("Kvarh;");// 当前B相组合无功1电能示值:100Kvarh;
        index = index + 4;
        resultString.append("当前B相组合无功2电能示值:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("Kvarh;");// 当前B相组合无功2电能示值:100Kvarh;
        index = index + 4;
        resultString.append("当前C相正向有功电能示值:").append(ProtocolGW_09Util.parseA14(byteValue, index)).append("kWh;");// 当前C相正向有功电能示值:100kWh;
        index = index + 5;
        resultString.append("当前C相反向有功电能示值:").append(ProtocolGW_09Util.parseA14(byteValue, index)).append("kWh;");// 当前C相反向有功电能示值:100kWh;
        index = index + 5;
        resultString.append("当前C相组合无功1电能示值:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("Kvarh;");// 当前C相组合无功1电能示值:100Kvarh;
        index = index + 4;
        resultString.append("当前C相组合无功2电能示值:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("Kvarh;");// 当前C相组合无功2电能示值:100Kvarh;
        index = index + 4;
        reqData.setValue(resultString.toString());
        return reqData;
    }

    private static ReqDataComm parseF27Frame(byte[] byteValue, int index) {
        ReqDataComm reqData = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        resultString.append("终端抄表时间:").append(ProtocolGW_09Util.parseA15(byteValue, index)).append(";");// 终端抄表时间:yyyy-MM-dd
        // HH:mm;
        index = index + 5;
        resultString.append("电能表日历时钟:").append(DateUtil.DateToLongStr(ProtocolGW_09Util.parseA1(byteValue, index))).append(";");// 电能表日历时钟:yyyy-MM-dd
        // HH:mm:ss;
        index = index + 6;
        resultString.append("电池工作时间:").append(ProtocolGW_09Util.parseA27(byteValue, index)).append("min;");// 电池工作时间:100min;
        index = index + 4;
        resultString.append("编程总次数:").append(ProtocolGW_09Util.parseA10(byteValue, index)).append("次;");// 电池工作时间:100次;
        index = index + 3;
        resultString.append("最近一次编程发生时刻:").append(DateUtil.DateToLongStr(ProtocolGW_09Util.parseA1(byteValue, index))).append(";");// 最近一次编程发生时刻:yyyy-MM-dd
        // HH:mm:ss;
        index = index + 6;
        resultString.append("电表清零总次数:").append(ProtocolGW_09Util.parseA10(byteValue, index)).append("次;");// 电表清零总次数:100次;
        index = index + 3;
        resultString.append("最近一次清零发生时刻:").append(DateUtil.DateToLongStr(ProtocolGW_09Util.parseA1(byteValue, index))).append(";");// 最近一次清零发生时刻:yyyy-MM-dd
        // HH:mm:ss;
        index = index + 6;
        resultString.append("需量清零总次数:").append(ProtocolGW_09Util.parseA10(byteValue, index)).append("次;");// 需量清零总次数:100次;
        index = index + 3;
        resultString.append("最近一次清零发生时刻:").append(DateUtil.DateToLongStr(ProtocolGW_09Util.parseA1(byteValue, index))).append(";");// 最近一次清零发生时刻:yyyy-MM-dd
        // HH:mm:ss;
        index = index + 6;
        resultString.append("事件清零总次数:").append(ProtocolGW_09Util.parseA10(byteValue, index)).append("次;");// 事件清零总次数:100次;
        index = index + 3;
        resultString.append("最近一次清零发生时刻:").append(DateUtil.DateToLongStr(ProtocolGW_09Util.parseA1(byteValue, index))).append(";");// 最近一次清零发生时刻:yyyy-MM-dd
        // HH:mm:ss;
        index = index + 6;
        resultString.append("校时总次数:").append(ProtocolGW_09Util.parseA10(byteValue, index)).append("次;");// 校时总次数:100次;
        index = index + 3;
        resultString.append("最近一次校时发生时刻:").append(DateUtil.DateToLongStr(ProtocolGW_09Util.parseA1(byteValue, index))).append(";");// 最近一次校时发生时刻:yyyy-MM-dd
        // HH:mm:ss;
        index = index + 6;
        reqData.setValue(resultString.toString());
        return reqData;
    }

    private static ReqDataComm parseF28Frame(byte[] byteValue, int index) {
        ReqDataComm reqData = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        resultString.append("终端抄表时间:").append(ProtocolGW_09Util.parseA15(byteValue, index)).append(";");// 终端抄表时间:yyyy-MM-dd
        // HH:mm;
        index = index + 5;
        // 电表运行状态字变位标志1
        resultString.append("电表运行状态字变位标志1:");
        int jisuan = ((byteValue[index] >> 1) & 0x01);
        resultString.append("需量积算方式:").append(jisuan).append(";");
        int shizhong = ((byteValue[index] >> 2) & 0x01);
        resultString.append("时钟电池:").append(shizhong).append(";");
        int dingdian = ((byteValue[index] >> 3) & 0x01);
        resultString.append("停电抄表电池:").append(dingdian).append(";");
        int ygfangxiang = ((byteValue[index] >> 4) & 0x01);
        resultString.append("有功功率方向:").append(ygfangxiang).append(";");
        int wgfangxiang = ((byteValue[index] >> 5) & 0x01);
        resultString.append("无功功率方向:").append(wgfangxiang).append(";");
        index = index + 2;
        // 电表运行状态字变位标志2
        resultString.append("电表运行状态字变位标志2:");
        int yougongA = byteValue[index] & 0x01;
        resultString.append("A相有功功率方向:").append(yougongA).append(";");
        int yougongB = ((byteValue[index] >> 1) & 0x01);
        resultString.append("B相有功功率方向:").append(yougongB).append(";");
        int yougongC = ((byteValue[index] >> 2) & 0x01);
        resultString.append("C相有功功率方向:").append(yougongC).append(";");
        int wugongA = ((byteValue[index] >> 4) & 0x01);
        resultString.append("A相无功功率方向:").append(wugongA).append(";");
        int wugongB = ((byteValue[index] >> 5) & 0x01);
        resultString.append("B相无功功率方向:").append(wugongB).append(";");
        int wugongC = ((byteValue[index] >> 6) & 0x01);
        resultString.append("C相无功功率方向:").append(wugongC).append(";");
        index = index + 2;
        // 电表运行状态字变位标志3
        resultString.append("电表运行状态字变位标志3:");
        int yunxing = byteValue[index] & 0x01;
        resultString.append("当前运行时段:").append(yunxing).append(";");
        int gongdian = ((byteValue[index] >> 1) & 0x03);
        resultString.append("供电方式:").append(gongdian).append(";");
        int buancheng = ((byteValue[index] >> 3) & 0x01);
        resultString.append("编程允许:").append(buancheng).append(";");
        int jidianqi = ((byteValue[index] >> 4) & 0x01);
        resultString.append("继电器状态:").append(jidianqi).append(";");
        index = index + 2;
        // 电表运行状态字变位标志4,5,6
        for (int i = 4; i <= 6; i++) {
            resultString.append("电表运行状态字变位标志字").append(i).append(":");
            int shiya = byteValue[index] & 0x01;
            resultString.append("失压:").append(shiya).append(";");
            int qianya = ((byteValue[index] >> 1) & 0x01);
            resultString.append("欠压:").append(qianya).append(";");
            int guoya = ((byteValue[index] >> 2) & 0x01);
            resultString.append("过压:").append(guoya).append(";");
            int shiliu = ((byteValue[index] >> 3) & 0x01);
            resultString.append("失流:").append(shiliu).append(";");
            int guoliu = ((byteValue[index] >> 4) & 0x01);
            resultString.append("过流:").append(guoliu).append(";");
            int guozai = ((byteValue[index] >> 5) & 0x01);
            resultString.append("过载:").append(guozai).append(";");
            int fanxiang = ((byteValue[index] >> 6) & 0x01);
            resultString.append("反向:").append(fanxiang).append(";");
            int duanxiang = ((byteValue[index] >> 7) & 0x01);
            resultString.append("断相:").append(duanxiang).append(";");
            index = index + 2;
        }
        // 电表运行状态字变位标志7
        resultString.append("电表运行状态字变位标志7:");
        int dianyani = byteValue[index] & 0x01;
        resultString.append("电压逆相序:").append(dianyani).append(";");
        int dianliuni = ((byteValue[index] >> 1) & 0x01);
        resultString.append("电流逆相序:").append(dianliuni).append(";");
        int dianyapin = ((byteValue[index] >> 2) & 0x01);
        resultString.append("电压不平衡:").append(dianyapin).append(";");
        int dianliupin = ((byteValue[index] >> 3) & 0x01);
        resultString.append("电流不平衡:").append(dianliupin).append(";");
        index = index + 2;
        /**
         * 电表运行状态字
         */
        resultString.append("电表运行状态字1:");
        jisuan = ((byteValue[index] >> 1) & 0x01);
        resultString.append("需量积算方式:").append(jisuan).append(";");
        shizhong = ((byteValue[index] >> 2) & 0x01);
        resultString.append("时钟电池:").append(shizhong).append(";");
        dingdian = ((byteValue[index] >> 3) & 0x01);
        resultString.append("停电抄表电池:").append(dingdian).append(";");
        ygfangxiang = ((byteValue[index] >> 4) & 0x01);
        resultString.append("有功功率方向:").append(ygfangxiang).append(";");
        wgfangxiang = ((byteValue[index] >> 5) & 0x01);
        resultString.append("无功功率方向:").append(wgfangxiang).append(";");
        index = index + 2;
        // 电表运行状态字2
        resultString.append("电表运行状态字2:");
        yougongA = byteValue[index] & 0x01;
        resultString.append("A相有功功率方向:").append(yougongA).append(";");
        yougongB = ((byteValue[index] >> 1) & 0x01);
        resultString.append("B相有功功率方向:").append(yougongB).append(";");
        yougongC = ((byteValue[index] >> 2) & 0x01);
        resultString.append("C相有功功率方向:").append(yougongC).append(";");
        wugongA = ((byteValue[index] >> 4) & 0x01);
        resultString.append("A相无功功率方向:").append(wugongA).append(";");
        wugongB = ((byteValue[index] >> 5) & 0x01);
        resultString.append("B相无功功率方向:").append(wugongB).append(";");
        wugongC = ((byteValue[index] >> 6) & 0x01);
        resultString.append("C相无功功率方向:").append(wugongC).append(";");
        index = index + 2;
        // 电表运行状态字3
        resultString.append("电表运行状态字3:");
        yunxing = byteValue[index] & 0x01;
        resultString.append("当前运行时段:").append(yunxing).append(";");
        gongdian = ((byteValue[index] >> 1) & 0x03);
        resultString.append("供电方式:").append(gongdian).append(";");
        buancheng = ((byteValue[index] >> 3) & 0x01);
        resultString.append("编程允许:").append(buancheng).append(";");
        jidianqi = ((byteValue[index] >> 4) & 0x01);
        resultString.append("继电器状态:").append(jidianqi).append(";");
        index = index + 2;
        // 电表运行状态字4,5,6
        for (int i = 4; i <= 6; i++) {
            resultString.append("电表运行状态字").append(i).append(":");
            int shiya = byteValue[index] & 0x01;
            resultString.append("失压:").append(shiya).append(";");
            int qianya = ((byteValue[index] >> 1) & 0x01);
            resultString.append("欠压:").append(qianya).append(";");
            int guoya = ((byteValue[index] >> 2) & 0x01);
            resultString.append("过压:").append(guoya).append(";");
            int shiliu = ((byteValue[index] >> 3) & 0x01);
            resultString.append("失流:").append(shiliu).append(";");
            int guoliu = ((byteValue[index] >> 4) & 0x01);
            resultString.append("过流:").append(guoliu).append(";");
            int guozai = ((byteValue[index] >> 5) & 0x01);
            resultString.append("过载:").append(guozai).append(";");
            int fanxiang = ((byteValue[index] >> 6) & 0x01);
            resultString.append("反向:").append(fanxiang).append(";");
            int duanxiang = ((byteValue[index] >> 7) & 0x01);
            resultString.append("断相:").append(duanxiang).append(";");
            index = index + 2;
        }
        // 电表运行状态字7
        resultString.append("电表运行状态字7:");
        dianyani = byteValue[index] & 0x01;
        resultString.append("电压逆相序:").append(dianyani).append(";");
        dianliuni = ((byteValue[index] >> 1) & 0x01);
        resultString.append("电流逆相序:").append(dianliuni).append(";");
        dianyapin = ((byteValue[index] >> 2) & 0x01);
        resultString.append("电压不平衡:").append(dianyapin).append(";");
        dianliupin = ((byteValue[index] >> 3) & 0x01);
        resultString.append("电流不平衡:").append(dianliupin).append(";");
        index = index + 2;
        reqData.setValue(resultString.toString());
        return reqData;
    }

    private static ReqDataComm parseF25Frame(byte[] byteValue, int index) {
        ReqDataComm reqData = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        resultString.append("终端抄表时间:").append(ProtocolGW_09Util.parseA15(byteValue, index)).append(";");// 终端抄表时间:yyyy-MM-dd
        index = index + 5;
        resultString.append("当前总有功功率:").append(ProtocolGW_09Util.parseA9(byteValue, index)).append("kW;");// 当前总有功功率:100kW;
        index = index + 3;
        resultString.append("当前A相有功功率:").append(ProtocolGW_09Util.parseA9(byteValue, index)).append("kW;");// 当前A相有功功率:100kW;
        index = index + 3;
        resultString.append("当前B相有功功率:").append(ProtocolGW_09Util.parseA9(byteValue, index)).append("kW;");// 当前B相有功功率:100kW;
        index = index + 3;
        resultString.append("当前C相有功功率:").append(ProtocolGW_09Util.parseA9(byteValue, index)).append("kW;");// 当前C相有功功率:100kW;
        index = index + 3;
        resultString.append("当前总无功功率:").append(ProtocolGW_09Util.parseA9(byteValue, index)).append("kW;");// 当前总无功功率:100kW;
        index = index + 3;
        resultString.append("当前A相无功功率:").append(ProtocolGW_09Util.parseA9(byteValue, index)).append("kW;");// 当前A相无功功率:100kW;
        index = index + 3;
        resultString.append("当前B相无功功率:").append(ProtocolGW_09Util.parseA9(byteValue, index)).append("kW;");// 当前B相无功功率:100kW;
        index = index + 3;
        resultString.append("当前C相无功功率:").append(ProtocolGW_09Util.parseA9(byteValue, index)).append("kW;");// 当前C相无功功率:100kW;
        index = index + 3;
        resultString.append("当前总功率因数:").append(ProtocolGW_09Util.parseA5(byteValue, index)).append("％;");// 当前总功率因数:50%;
        index = index + 2;
        resultString.append("当前A相功率因数:").append(ProtocolGW_09Util.parseA5(byteValue, index)).append("％;");// 当前A相功率因数:50%;
        index = index + 2;
        resultString.append("当前B相功率因数:").append(ProtocolGW_09Util.parseA5(byteValue, index)).append("％;");// 当前B相功率因数:50%;
        index = index + 2;
        resultString.append("当前C相功率因数:").append(ProtocolGW_09Util.parseA5(byteValue, index)).append("％;");// 当前C相功率因数:50%;
        index = index + 2;
        resultString.append("当前A相电压:").append(ProtocolGW_09Util.parseA7(byteValue, index)).append("V;");// 当前A相电压:1V;
        index = index + 2;
        resultString.append("当前B相电压:").append(ProtocolGW_09Util.parseA7(byteValue, index)).append("V;");// 当前B相电压:1V;
        index = index + 2;
        resultString.append("当前C相电压:").append(ProtocolGW_09Util.parseA7(byteValue, index)).append("V;");// 当前C相电压:1V;
        index = index + 2;
        resultString.append("当前A相电流:").append(ProtocolGW_09Util.parseA25(byteValue, index)).append("A;");// 当前A相电流:1A;
        index = index + 3;
        resultString.append("当前B相电流:").append(ProtocolGW_09Util.parseA25(byteValue, index)).append("A;");// 当前B相电流:1A;
        index = index + 3;
        resultString.append("当前C相电流:").append(ProtocolGW_09Util.parseA25(byteValue, index)).append("A;");// 当前C相电流:1A;
        index = index + 3;
        resultString.append("当前零序电流:").append(ProtocolGW_09Util.parseA25(byteValue, index)).append("A;");// 当前零序电流:1A;
        index = index + 3;
        resultString.append("当前总视在功率:").append(ProtocolGW_09Util.parseA9(byteValue, index)).append("kVA;");// 当前总视在功率:1kVA;
        index = index + 3;
        resultString.append("当前A相视在功率:").append(ProtocolGW_09Util.parseA9(byteValue, index)).append("kVA;");// 当前A相视在功率:1kVA;
        index = index + 3;
        resultString.append("当前B相视在功率:").append(ProtocolGW_09Util.parseA9(byteValue, index)).append("kVA;");// 当前B相视在功率:1kVA;
        index = index + 3;
        resultString.append("当前C相视在功率:").append(ProtocolGW_09Util.parseA9(byteValue, index)).append("kVA;");// 当前C相视在功率:1kVA;
        reqData.setValue(resultString.toString());
        return reqData;
    }

    private static ReqDataComm parseF8Frame(byte[] byteValue, int index) {
        ReqDataComm reqDataComm = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        int num = 1;
        for (int i = 0; i < 8; i++) {
            String bytestring = ProtocolUtils.hex2Bin(byteValue[index++]);
            for (int j = 0; j < 8; j++) {
                String status = bytestring.substring(7 - j, 8 - j);
                resultString.append("ERC" + num + ":" + (status.equals("1") ? "有事件" : "无事件") + ";");
                num++;
            }
        }
        reqDataComm.setValue(resultString.toString());
        return reqDataComm;
    }

    private static ReqDataComm parseF9Frame(byte[] byteValue, int index) {
        ReqDataComm reqDataComm = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        String st = ProtocolUtils.hex2Bin(byteValue[index++]);
        for (int i = 0; i < 8; i++) {
            String ststatus = st.substring(7 - i, 8 - i);
            resultString.append("ST" + (i + 1) + "状态:" + (ststatus.equals("1") ? "合" : "分") + ";");
        }
        String cd = ProtocolUtils.hex2Bin(byteValue[index++]);
        for (int i = 0; i < 8; i++) {
            String cdstatus = cd.substring(7 - i, 8 - i);
            resultString.append("CD" + (i + 1) + "状态:" + (cdstatus.equals("1") ? "有变化" : "无变化") + ";");
        }
        reqDataComm.setValue(resultString.toString());
        return reqDataComm;
    }

    private static ReqDataComm parseF10Frame(byte[] byteValue, int index) {
        ReqDataComm reqDataComm = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        resultString.append("终端与主站当日通信流量:" + ProtocolUtils.byteToInteger(byteValue, index) + ";");
        index = index + 4;
        resultString.append("终端与主站当月通信流量:" + ProtocolUtils.byteToInteger(byteValue, index) + ";");
        reqDataComm.setValue(resultString.toString());
        return reqDataComm;
    }

    private static ReqDataComm parseF11Frame(byte[] byteValue, int index) {
        ReqDataComm reqDataComm = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        int num = ProtocolUtils.Unsignd(byteValue[index++]);
        resultString.append("本项数据块个数:" + num + ";");
        for (int i = 0; i < num; i++) {
            resultString.append("终端通信端口号:" + ProtocolUtils.Unsignd(byteValue[index++]) + ";");
            resultString.append("要抄电表总数:" + ProtocolUtils.byteToShort(byteValue[index + 1], byteValue[index]) + ";");
            index = index + 2;
            resultString.append(((byteValue[index] & 0x01) == 1) ? "抄表忙/闲标志位:正在抄表;" : "抄表忙/闲标志位:未抄表;");
            resultString.append(((byteValue[index] & 0x02) == 2) ? "抄表任务时段内完成/未完成标志位:时段内完成;" : "抄表任务时段内完成/未完成标志位:时段内未完成;");
            index++;
            resultString.append("抄表成功块数:" + ProtocolUtils.byteToShort(byteValue[index + 1], byteValue[index]) + ";");
            index = index + 2;
            resultString.append("抄重点表成功块数:" + ProtocolUtils.Unsignd(byteValue[index++]) + ";");
            resultString.append("抄表开始时间:" + DateUtil.DateToLongStr(ProtocolGW_09Util.parseA1(byteValue, index)) + ";");// 抄表开始时间:yyyy-MM-dd
            // HH:mm:ss;
            index = index + 6;
            resultString.append("抄表结束时间:" + DateUtil.DateToLongStr(ProtocolGW_09Util.parseA1(byteValue, index)) + ";");// 抄表结束时间:yyyy-MM-dd
            // HH:mm:ss;
            index = index + 6;
        }
        reqDataComm.setValue(resultString.toString());
        return reqDataComm;
    }

    private static ReqDataComm parseF7Frame(byte[] byteValue, int index) {
        ReqDataComm reqData = new ReqDataComm();
        Req1stDataF7 f7 = new Req1stDataF7();
        reqData.setData(f7);
        StringBuffer resultString = new StringBuffer("");
        Map<String, Object> data = new HashMap<String, Object>();
        resultString.append("重要事件计数器EC1值:" + ProtocolUtils.Unsignd(byteValue[index]) + ";");
        f7.setEc1((short) ProtocolUtils.Unsignd(byteValue[index]));
        index++;
        resultString.append("重要事件计数器EC2值:" + ProtocolUtils.Unsignd(byteValue[index]) + ";");
        f7.setEc2((short) ProtocolUtils.Unsignd(byteValue[index]));
        index++;
        reqData.setData(f7);
        reqData.setValue(resultString.toString());
        return reqData;
    }

    private static ReqDataComm parseF6Frame(byte[] byteValue, int index) {
        ReqDataComm reqDataComm = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        String telecontroltrip = ProtocolUtils.hex2Bin(byteValue[index++]);
        resultString.append("遥控跳闸输出状态:");
        for (int i = 0; i < 8; i++) {// 遥控跳闸输出状态
            if ("1".equals(telecontroltrip.substring(7 - i, 8 - i))) {
                resultString.append(i + 1).append("轮次遥控跳闸输出状态:跳闸,");
            } else {
                resultString.append(i + 1).append("轮次遥控跳闸输出状态:合闸,");
            }
        }
        resultString.append(";");
        // 当前催费告警状态
        if ((byteValue[index++] & 0x01) == 1) {
            resultString.append("终端当前是否处于催费告警状态:处于;");
        } else {
            resultString.append("终端当前是否处于催费告警状态:未处于;");
        }
        String sign = ProtocolUtils.hex2Bin(byteValue[index++]);
        for (int i = 0; i < 8; i++) {// 总加组有效标志位
            String flag = sign.substring(7 - i, 8 - i);
            if ("1".equals(flag)) {
                resultString.append("总加组").append(i + 1).append(":");
                resultString.append("当前功控定值:").append(toString(ProtocolGW_09Util.parseA2(byteValue, index))).append(";");
                index = index + 2;
                resultString.append("当前功率下浮控浮动系数:").append(toString(ProtocolGW_09Util.parseA4(byteValue, index))).append(";");
                index = index + 1;
                // 功控跳闸输出状态
                String powertripstatus = ProtocolUtils.hex2Bin(byteValue[index++]);
                for (int k = 0; k < 8; k++) {// 功控时段有效标志位
                    if ("1".equals(powertripstatus.substring(7 - k, 8 - k))) {
                        resultString.append(k + 1).append("轮次功控跳闸输出状态:处于;");
                    } else {
                        resultString.append(k + 1).append("轮次功控跳闸输出状态:未处于;");
                    }
                }
                // 月电控跳闸输出状态
                String electripstatus = ProtocolUtils.hex2Bin(byteValue[index++]);
                for (int k = 0; k < 8; k++) {// 功控时段有效标志位
                    if ("1".equals(electripstatus.substring(7 - k, 8 - k))) {
                        resultString.append(k + 1).append("轮次月电控跳闸输出状态:处于;");
                    } else {
                        resultString.append(k + 1).append("轮次月电控跳闸输出状态:未处于;");
                    }
                }
                // 购电控跳闸输出状态
                String busselectripstatus = ProtocolUtils.hex2Bin(byteValue[index++]);
                for (int k = 0; k < 8; k++) {// 功控时段有效标志位
                    if ("1".equals(busselectripstatus.substring(7 - k, 8 - k))) {
                        resultString.append(k + 1).append("轮次购电控跳闸输出状态:处于;");
                    } else {
                        resultString.append(k + 1).append("轮次购电控跳闸输出状态:未处于;");
                    }
                }
                // 功控越限告警状态
                int period = byteValue[index] & 0x01;
                resultString.append(period == 1 ? "时段控:处于;" : "时段控:未处于;");
                int rest = ((byteValue[index] & 0x02) >> 1);
                resultString.append(rest == 1 ? "厂休控:处于;" : "厂休控:未处于;");
                int bussiness = ((byteValue[index] & 0x04) >> 2);
                resultString.append(bussiness == 1 ? "营业报停控:处于;" : "营业报停控:未处于;");
                int floating = ((byteValue[index] & 0x08) >> 3);
                resultString.append(floating == 1 ? "当前功率下浮控:处于;" : "当前功率下浮控:未处于;");
                index++;
                // 电控越限告警状态
                int monthelec = byteValue[index] & 0x01;
                resultString.append(monthelec == 1 ? "月电控:处于;" : "月电控:未处于;");
                int purchelec = ((byteValue[index] & 0x02) >> 1);
                resultString.append(purchelec == 1 ? "购电控:处于;" : "购电控:未处于;");
                index++;
            }
        }
        reqDataComm.setValue(resultString.toString());
        return reqDataComm;
    }

    private static String toString(BigDecimal value) {
        if (value == null) {
            return "";
        }
        return value.toString();
    }

    private static ReqDataComm parseF5Frame(byte[] byteValue, int index) {
        ReqDataComm reqDataComm = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        int paulele = byteValue[index] & 0x01;
        resultString.append(paulele == 1 ? "保电状态:投入;" : "保电状态:解除;");
        int cutout = ((byteValue[index] & 0x02) >> 1);
        resultString.append(cutout == 1 ? "剔除状态:投入;" : "剔除状态:解除;");
        int report = ((byteValue[index] & 0x04) >> 2);
        resultString.append(report == 1 ? "催费告警状态:投入;" : "催费告警状态:解除;");
        index++;
        String sign = ProtocolUtils.hex2Bin(byteValue[index++]);
        for (int i = 0; i < 8; i++) {
            String flag = sign.substring(7 - i, 8 - i);
            if ("1".equals(flag)) {
                resultString.append("功控定值方案号:").append((byteValue[index++] & 0x03)).append(";");
                String Powercontrolperiod = ProtocolUtils.hex2Bin(byteValue[index++]);
                for (int k = 0; k < 8; k++) {// 功控时段有效标志位
                    if ("1".equals(Powercontrolperiod.substring(7 - k, 8 - k))) {
                        resultString.append(k + 1).append("时段控投入的有效时段:有效;");
                    } else {
                        resultString.append(k + 1).append("时段控投入的有效时段:无效;");
                    }
                }
                // 功控状态
                int period = byteValue[index] & 0x01;
                resultString.append(period == 1 ? "时段控:投入;" : "时段控:解除;");
                int rest = ((byteValue[index] & 0x02) >> 1);
                resultString.append(rest == 1 ? "厂休控:投入;" : "厂休控:解除;");
                int bussiness = ((byteValue[index] & 0x04) >> 2);
                resultString.append(bussiness == 1 ? "营业报停控:投入;" : "营业报停控:解除;");
                int floating = ((byteValue[index] & 0x08) >> 3);
                resultString.append(floating == 1 ? "当前功率下浮控:投入;" : "当前功率下浮控:解除;");
                index++;
                // 电控状态
                int monthelec = byteValue[index] & 0x01;
                resultString.append(monthelec == 1 ? "月电控:投入;" : "月电控:解除;");
                int purchelec = ((byteValue[index] & 0x02) >> 1);
                resultString.append(purchelec == 1 ? "购电控:投入;" : "购电控:解除;");
                index++;
                // 功控轮次状态
                String powerturnstatus = ProtocolUtils.hex2Bin(byteValue[index++]);
                for (int k = 0; k < 8; k++) {// 功控时段有效标志位
                    if ("1".equals(powerturnstatus.substring(7 - k, 8 - k))) {
                        resultString.append(k + 1).append("轮次开关的功控受控状态:受控;");
                    } else {
                        resultString.append(k + 1).append("轮次开关的功控受控状态:不受控;");
                    }
                }
                // 电控轮次状态
                String electurnstatus = ProtocolUtils.hex2Bin(byteValue[index++]);
                for (int k = 0; k < 8; k++) {// 功控时段有效标志位
                    if ("1".equals(electurnstatus.substring(7 - k, 8 - k))) {
                        resultString.append(k + 1).append("轮次开关的电控受控状态:受控;");
                    } else {
                        resultString.append(k + 1).append("轮次开关的电控受控状态:不受控;");
                    }
                }
            }
        }
        reqDataComm.setValue(resultString.toString());
        return reqDataComm;
    }

    private static ReqDataComm parseF4Frame(byte[] byteValue, int index) {
        ReqDataComm reqDataComm = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        int isActiveReport = byteValue[index] & 0x03;
        if (isActiveReport == 1) {
            resultString.append("上行状态:允许主动上报;");
        } else if (isActiveReport == 2) {
            resultString.append("上行状态:禁止主动上报;");
        } else {
            resultString.append("上行状态:无效;");
        }
        int isComm = ((byteValue[index] & 0x0C) >> 2);
        if (isComm == 1) {
            resultString.append("通信状态:允许通信;");
        } else if (isComm == 2) {
            resultString.append("通信状态:禁止通信;");
        } else {
            resultString.append("通信状态:无效;");
        }
        reqDataComm.setValue(resultString.toString());
        return reqDataComm;
    }

    private static ReqDataComm parseF3Frame(byte[] byteValue, int index) {
        ReqDataComm reqDataComm = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        int num = 1;
        for (int i = 0; i < 31; i++) {
            String bytestring = ProtocolUtils.hex2Bin(byteValue[index++]);
            for (int j = 0; j < 8; j++) {
                String status = bytestring.substring(7 - j, 8 - j);
                resultString.append("F").append(num).append(":").append(status).append(";");
                num++;
            }
        }
        reqDataComm.setValue(resultString.toString());
        return reqDataComm;
    }

    private static ReqDataComm parseF129_132Frame(byte[] byteValue, int index, int fn) {
        ReqDataComm reqData = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        resultString.append("终端抄表时间:").append(ProtocolGW_09Util.parseA15(byteValue, index)).append(";");// 终端抄表时间:yyyy-MM-dd
        // HH:mm;
        index = index + 5;
        int tariffnum = ProtocolUtils.Unsignd(byteValue[index++]);
        if (tariffnum ==0 || tariffnum > 96) {
            tariffnum = TARIFF_NUM_DEFAULT;
        }
        resultString.append("费率数:").append(tariffnum).append(";");// 费率数:1;
        if (fn == 129) {
            resultString.append("当前正向有功电能示值").append(":").append(ProtocolGW_09Util.parseA14(byteValue, index)).append(";");
            index = index + 5;
            for (int i = 0;i < tariffnum; i++) {
                resultString.append("费率").append((i + 1)).append("当前正向有功电能示值").append(":").append(ProtocolGW_09Util.parseA14(byteValue, index)).append(";");// 费率i正向有功电能示值:100kWh;
                index = index + 5;
            }
        } else if (fn == 130) {
            resultString.append("当前正向无功（组合无功1）电能示值").append(":").append(ProtocolGW_09Util.parseA11(byteValue, index)).append(";");
            index = index + 4;
            for (int i = 0;i < tariffnum; i++) {
                resultString.append("费率").append((i + 1)).append("当前正向无功（组合无功1）电能示值").append(":").append(ProtocolGW_09Util.parseA11(byteValue, index)).append(";");// 费率i正向有功电能示值:100kWh;
                index = index + 4;
            }
        } else if (fn == 131) {
            resultString.append("当前反向有功电能示值").append(":").append(ProtocolGW_09Util.parseA14(byteValue, index)).append(";");
            index = index + 5;
            for (int i = 0;i < tariffnum; i++) {
                resultString.append("费率").append((i + 1)).append("当前反向有功电能示值").append(":").append(ProtocolGW_09Util.parseA14(byteValue, index)).append(";");// 费率i正向有功电能示值:100kWh;
                index = index + 5;
            }
        } else if (fn == 132) {
            resultString.append("当前反向无功（组合无功1）电能示值").append(":").append(ProtocolGW_09Util.parseA11(byteValue, index)).append(";");
            index = index + 4;
            for (int i = 0;i < tariffnum; i++) {
                resultString.append("费率").append((i + 1)).append("当前反向无功（组合无功1）电能示值").append(":").append(ProtocolGW_09Util.parseA11(byteValue, index)).append(";");// 费率i正向有功电能示值:100kWh;
                index = index + 4;
            }
        }
        reqData.setValue(resultString.toString());
        return reqData;
    }

    private static String Td_h(byte[] byteValue, int index) {
        StringBuffer resultString = new StringBuffer("");
        resultString.append("上一整点的小时时间:").append(String.format("%02X", byteValue[index++])).append(";");//
        int freezeTime = ProtocolUtils.byteToInteger(byteValue, index);// 数据冻结密度m
        resultString.append("冻结间隔时间:");
        if (freezeTime == 0) {
            resultString.append("不冻结;");
        } else if (freezeTime == 1) {
            resultString.append("15 min;");
        } else if (freezeTime == 2) {
            resultString.append("30 min;");
        } else if (freezeTime == 3) {
            resultString.append("60 min;");
        } else if (freezeTime == 254) {
            resultString.append("5 min;");
        } else if (freezeTime == 255) {
            resultString.append("1 min;");
        } else {
            resultString.append("备用;");
        }
        index++;
        return resultString.toString();
    }
}
